﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using System.Security.Cryptography;

namespace AdvEditor
{
    public class ProjectData
    {
        public string Name { get; set; }
        public string GameTitle { get; set; }
        public string InitialScenario { get; set; }
        public Size WindowSize { get; set; }
        public byte[] RijndaelKey { get; set; }
        public byte[] RijndaelIV { get; set; }

        /// <summary>
        /// 初期化
        /// </summary>
        public ProjectData()
        {
            Name = "";
            GameTitle = "";
            InitialScenario = "init.scn";
            WindowSize = new Size(640, 480);
            RijndaelManaged rijndael = new RijndaelManaged();
            rijndael.GenerateIV();
            rijndael.GenerateKey();
            RijndaelKey = rijndael.Key;
            RijndaelIV = rijndael.IV;
        }

        /// <summary>
        /// ファイルから読み込んで返す
        /// </summary>
        /// <param name="fileName"></param>
        public static ProjectData Load(string fileName)
        {            
            using(FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)){
                XmlSerializer serializer = new XmlSerializer(typeof(ProjectData));
                return serializer.Deserialize(fs) as ProjectData;
            }
        }

        /// <summary>
        /// このオブジェクトの内容をXMLで書き込む
        /// </summary>
        /// <param name="fileName"></param>
        public void Save(string fileName)
        {            
            using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) {
                XmlSerializer serializer = new XmlSerializer(this.GetType());
                serializer.Serialize(fs, this);
            }
        }
    }
}
